package org.distributed.transaction.core.context;

import java.io.Serializable;
import java.lang.reflect.Method;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

/**
 * 事务信息
 */
public class TransactionInfo implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 事务 提交/回滚 执行类
	 */
	private Class<?> executeClass;

	/**
	 * 参数
	 */
	private Object[] methodParameter;

	/**
	 * 参数类型
	 */
	private Class[] methodTypeParameter;
	
	/**
     * 用户实例对象的业务方法（包含注解信息）
     */
    private Method businessMethod;
    
    public TransactionInfo() {}
    
    public TransactionInfo(ProceedingJoinPoint point) throws Throwable {
    	MethodSignature methodSignature = (MethodSignature) point.getSignature();
		Method method = methodSignature.getMethod();
		Class<?> targetClass = point.getTarget().getClass();
		Method bussinessMethod = targetClass.getMethod(method.getName(), method.getParameterTypes());
		
		this.executeClass = targetClass;
		this.methodTypeParameter = bussinessMethod.getParameterTypes();
		this.methodParameter = point.getArgs();
		this.businessMethod = bussinessMethod;
    }

	public Class<?> getExecuteClass() {
		return executeClass;
	}

	public void setExecuteClass(Class<?> executeClass) {
		this.executeClass = executeClass;
	}

	public Object[] getMethodParameter() {
		return methodParameter;
	}

	public void setMethodParameter(Object[] methodParameter) {
		this.methodParameter = methodParameter;
	}

	public Class[] getMethodTypeParameter() {
		return methodTypeParameter;
	}

	public void setMethodTypeParameter(Class[] methodTypeParameter) {
		this.methodTypeParameter = methodTypeParameter;
	}

	public Method getBusinessMethod() {
		return businessMethod;
	}

	public void setBusinessMethod(Method businessMethod) {
		this.businessMethod = businessMethod;
	}

}
